package com.stu.design_patterns.singleton;

public class Singleton02Lazy {
  private static volatile Singleton02Lazy singleton;
  private Singleton02Lazy() {}
  // 在方法上加锁的缺点：不论是否存在实例，每个线程要想获取实例，就必须获取锁。所以效率低下。
  public static synchronized Singleton02Lazy getInstance() {
    if(singleton == null) singleton = new Singleton02Lazy();
    return singleton;
  }
  public void say() { System.out.println("懒汉式"); }
}
